<template>
  <div>
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item :label="$t('m.bpm.entity.processDefName')">
              <a-input placeholder="" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{ $t('m.common.button.query') }}</a-button>
              <a-button type="default" @click="searchReset" icon="reload" style="margin-left: 8px">{{ $t('m.common.button.reset') }}</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      @change="handleTableChange">
        <template slot="serialNum" slot-scope="text,record,index">
          {{(ipagination.current-1) * ipagination.pageSize + parseInt(index) + 1}}
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleStart(record.id)">{{ $t('m.bpm.other.fa-qi') }}</a>
          <!--<a-divider type="vertical"/>
          <a @click="handleStart2(record.id)">发起2</a>-->
        </span>

    </a-table>

    <redirect-modal ref="startForm"></redirect-modal>
  </div>
</template>

<script>

  import { YcListMixin } from '@/mixins/YcListMixin'
  import { filterMultiDictText } from '@/components/dict/YchDictSelectUtil'
  import RedirectModal from './redirect/RedirectModal'
  import { BpmConstant } from './BpmConstant'
  import YchConstant from "@/api/YchConstant";

  export default {
    name: 'StartProcessList',
    mixins: [YcListMixin],
    components: {
      RedirectModal
    },
    data () {
      return {
        columns: [
          {
            title:this.$t('m.common.label.number'),
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            scopedSlots: { customRender: 'serialNum' },
          },
          {
            title: this.$t('m.bpm.entity.name'),
            align: 'center',
            width: 180,
            dataIndex: 'name'
          },
          {
            title: this.$t('m.bpm.entity.version'),
            align: 'center',
            width: 80,
            dataIndex: 'version'
          },
          {
            title: this.$t('m.bpm.entity.status'),
            align: 'center',
            width: 80,
            dataIndex: 'status',
            customRender: (text) => {
              if (!text) {
                return ''
              } else {
                return filterMultiDictText(BpmConstant.processDefStatus, text)
              }
            }
          },
          {
            title: this.$t('m.system.category.entity.name'),
            align: 'center',
            width: 180,
            dataIndex: 'catalogName'
          },
          {
            title: this.$t('m.common.label.operate'),
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' },
            width: 120
          }
        ],
        url: {
          list: YchConstant.PREFIX_BPM + '/bpm-front/displayRest/getProcessDefListByPage/v1'
        }
      }
    },
    inject: ['addRouter'],
    methods: {
      handleStart (id) {
        let router = null
        if (this.$store.getters.formOpenType === '2') {
          router = this.addRouter({
            path: '/bpm/addFromProcess/' + id,
            component: resolve => require(['@/views/bpm/redirect/RedirectTab.vue'], resolve),
            props: {
              id: id,
              func: 'addFromProcess',
            },
            meta: {
              title: this.$t('m.common.button.addFlow'),
            }
          }, true);
          if (router) {
            this.$router.push(router).catch(err => {})
          }
        }
        if (!router) {
          this.$refs.startForm.addFromProcess(id)
        }
      },
    }
  }
</script>

<style lang="less" scoped>

</style>
